unit ulogin;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ButtonPanel,
  StdCtrls, process;

type

  { TLoginForm }

  TLoginForm = class(TForm)
    ButtonPanel1: TButtonPanel;
    ComboBox1: TComboBox;
    Edit1: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    StaticText1: TStaticText;
    procedure CancelButtonClick(Sender: TObject);
    procedure ComboBox1GetItems(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure HelpButtonClick(Sender: TObject);
    procedure OKButtonClick(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  LoginForm: TLoginForm;

implementation
 uses udata, umain;
{$R *.lfm}

{ TLoginForm }

procedure TLoginForm.FormCreate(Sender: TObject);
begin
 StaticText1.Caption:= INI.ReadString('DB','FILE','');
 DataModule1.DIC_SQLQuery.Close;
 DataModule1.DIC_SQLQuery.SQL.Clear;
 DataModule1.DIC_SQLQuery.SQL.Add('select * from users');
 DataModule1.DIC_SQLQuery.Open;
 while not DataModule1.DIC_SQLQuery.EOF do begin
   ComboBox1.Items.Add(DataModule1.DIC_SQLQuery.FieldByName('USERNAME').AsString);
   DataModule1.DIC_SQLQuery.Next;
 end;
 ComboBox1.Text:=INI.ReadString('DB','LASTUSER',ComboBox1.Items[0]);
 Edit1.Clear;
end;

procedure TLoginForm.HelpButtonClick(Sender: TObject);
var AProcess : Tprocess;
begin
 AProcess := TProcess.Create(nil);
 // Сообщим AProcess сомандную строку для запуска
 AProcess.CommandLine :=INI.ReadString('MODULES','ADMIN','');
 Application.MainForm.Visible:=false;
 AProcess.Options := AProcess.Options + [poWaitOnExit];
 AProcess.Execute;
 AProcess.Free;
 Application.MainForm.Visible:=true;
end;

procedure TLoginForm.OKButtonClick(Sender: TObject);
begin
  DataModule1.DIC_SQLQuery.Locate('USERNAME',ComboBox1.Text,[]);
  if Edit1.Text<>DataModule1.DIC_SQLQuery.FieldByName('PASS').AsString then begin
    ShowMessage('Введено невірний пароль!');
    Exit;
  end;
  INI.WriteString('DB','LASTUSER',ComboBox1.Text);
  Hide;
  golovna.Show;
end;

procedure TLoginForm.CancelButtonClick(Sender: TObject);
begin
  Application.Terminate;
end;

procedure TLoginForm.ComboBox1GetItems(Sender: TObject);
begin
  Edit1.SetFocus;
end;

end.

